<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			.dom {
				width: 100%;
				height: 400px;
				border: 1px solid red;
			}
		</style>
	</head>

	<body>
		<div class="dom">dom1</div>
		<div class="dom">dom2</div>
		<div class="dom">dom3</div>
		<div class="dom">dom4</div>
		<div class="dom">dom5</div>
		<div class="dom">dom6</div>
		<div class="dom">dom7</div>
		<div class="dom">dom8</div>
		<div class="dom">dom9</div>
		<div class="dom">dom10</div>
		<script>
			let observer = new IntersectionObserver((e) => {
				e.forEach((dom) => {
                    console.log(dom.isIntersecting, '----dom');
					// isIntersecting为true则dom出现在页面上
					dom.isIntersecting
						? (dom.target.style.width = '100px')
						: '';
				});
			}, {});
			let doms = document.getElementsByClassName('dom');

			for (let dom of doms) {
				observer.observe(dom);
			}
		</script>
	</body>
</html>
